import { getMetaData } from '../src/meta-data';
import {expect} from 'chai'

describe('getMetaData', () => {
    const originalEnv = process.env;

    beforeEach(() => {
        // 为每个测试用例重置环境变量
        process.env = { ...originalEnv };
    });



    it('should return all environment variables when they are set', () => {
        process.env['WORK_SPACE'] = 'test_workspace';
        process.env['BUILD_JOB_ID'] = '12345';
        process.env['BUILD_NUMBER'] = '67890';
        process.env['PIPELINE_ID'] = 'pipeline123';
        process.env['PIPELINE_NAME'] = 'Pipeline Name';
        process.env['EXECUTOR_ID'] = 'executor123';
        process.env['EXECUTOR_NAME'] = 'Executor Name';
        process.env['SOURCES'] = '{}';
        process.env['source'] = 'sourceValue';
        process.env['CI_COMMIT_ID'] = 'commitId';
        process.env['CI_COMMIT_REF_NAME'] = 'refName';
        process.env['CI_COMMIT_SHA'] = 'commitSha';
        process.env['CI_COMMIT_TITLE'] = 'commitTitle';

        const metaData = getMetaData();

        expect(metaData.buildJobId).equal('12345');
        expect(metaData.buildNumber).equal('67890');
        expect(metaData.pipelineId).equal('pipeline123');
        expect(metaData.pipelineName).equal('Pipeline Name');
        expect(metaData.executorId).equal('executor123');
        expect(metaData.executorName).equal('Executor Name');
        expect(metaData.sourceValue).equal('sourceValue');
        expect(metaData.ciCommitId).equal('commitId');
        expect(metaData.ciCommitRefName).equal('refName');
        expect(metaData.ciCommitSha).equal('commitSha');
        expect(metaData.ciCommitTitle).equal('commitTitle');
    });


});
